package com.ruoyi.framework.task;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.project.inventory.domain.RyInventory;
import com.ruoyi.project.inventory.mapper.RyInventoryMapper;
import com.ruoyi.project.inventory.service.IRyInventoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/*
 * @Description:个人标识
 * @ClassName：FirstLetterTask
 * @Author: 明月 萧雪
 * @Date: 2023/2/25 14:25:42
 */
@Component("firstLetterTask")
public class FirstLetterTask {

    @Autowired
    private IRyInventoryService iRyInventoryService;

    @Autowired
    private RyInventoryMapper ryInventoryMapper;

    public void firstTask(){
        try{
            int count = 0;
            int k = 0;
            int d = 0;

            List<RyInventory> all = ryInventoryMapper.all();
            for (RyInventory ryInventory : all) {
                if (StringUtils.isNotBlank(ryInventory.getName())) {
                    System.out.println(123);
                    int i = iRyInventoryService.updateRyInventory(ryInventory);
                    if (i>0) {
                        count++;
                        System.out.println(ryInventory.getName() + "首字母已添加！");
                    }else{
                        k++;
                        System.out.println(ryInventory.getName() + "首字母添加失败！");
                    }
                }else{
                    d++;
                    System.out.println("物品名称获取失败！");
                }
            }
            System.out.println("已完成物品信息库首字母添加，共计："+count);
            System.out.println("首字母添加失败，共计："+k);
            System.out.println("物品名称获取失败，共计："+d);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
